package anims.circle_bounce_;
/**
 * @author Christopher C Whiting
 * 3/26/07
 * Version 1.0
 * 
 * Circle class creates a circle, assigning it various properties like size, radius, and location, etc.
 * 	Includes set and get methods to collect or describe a circle which is created in the main program
 * 	Contains moving methods in order to make circles move around on screen.
 */


import java.awt.event.MouseEvent;

import anims.xxEllipse;

/**
 * Circle -- Draggable circles specified by center and radius
 */
public class Circle extends Ellipse {
    private int _cx, _cy, _radius, _xVelocity, _yVelocity;
 /** 
     * Constructor -- builds a circle at center (x,y) of radius r
     */
    public Circle (int x, int y, int r, int xVelocity, int yVelocity) {
	super(); // calls the Ellipse constructor
		_cx = x;
		_cy = y;
		_radius = r;
		_xVelocity = xVelocity;
		_yVelocity = yVelocity;
	}
    
	/**
	 * ACCESSOR METHODS
	 */
	// returns the X position of a circle
    public int getXCenter() {
		return _cx;
    }
	// returns the Y position of a circle
    public int getYCenter() {
		return _cy;
    }
	// returns the radius of a circle
    public int getRadius(){
		return _radius;
    }
	// returns the X velocity of a circle
    public int getXVelocity() {
		return _xVelocity;
    }
	// returns the Y velocity of a circle
    public int getYVelocity() {
		return _yVelocity;
    }

	/**
	* MUTATOR METHODS:
	*/
    // sets center of circle
    public void setCenter(int x, int y) {
		_cx = x;
		_cy = y;
		this.setLocation(_cx-_radius, _cy-_radius);
    }
    
    // sets radius of circle
    public void setRadius(int r){
		_radius = r;
		this.setLocation(_cx-_radius, _cy-_radius);
		this.setSize(2*r, 2*r);
    }

    // changes velocity
    public void setVelocity(){
		_xVelocity = -_xVelocity;
		_yVelocity = -_yVelocity;
		//System.out.println("setVelocity METHOD");
    }
          
    // changes location of circle so user can drag circle around screen
    public void mouseDragged(MouseEvent e){
		int x = e.getX();
		int y = e.getY();
		int r = this.getRadius();
		this.setCenter(x,y);
		this.setRadius(r);
	}
	
	//changes the velocity depending on what side is hit --> more realistic collisions
	public void rightSide(){
		_xVelocity = -_xVelocity;
	}
	public void leftSide(){
		_xVelocity = -_xVelocity;
	}
	public void topSide(){
		_yVelocity = -_yVelocity;
	}
	public void bottomSide(){
		_yVelocity = -_yVelocity;
	}
	
    //checks for boundary hits
	public void wallBounce(Circle c){
		int x = this.getXCenter();
		int y = this.getYCenter();
		int r = this.getRadius();
		System.out.println(x + ", " + y + "," + r + "," + _xVelocity + "," + _yVelocity);
		//System.out.println("wallBounce is being used");
		
		// side hits
		if (x + r + _xVelocity <= 0){
			this.leftSide();
			System.out.println("LEFT SIDE");		
		}
		if (x + r + _xVelocity >= 700){
			this.rightSide();
			System.out.println("RIGHT SIDE");
		}
		
		// top and bottom hits
		if (y + r + _yVelocity <= 0 ){
			this.topSide();
			System.out.println("TOP SIDE");
		}
		if (y + r + _yVelocity >= 500){
			this.bottomSide();
			System.out.println("BOTTOM SIDE");
		}
	}

    // moves circle a certain distance
    public void move(){
		int x = this.getXCenter();
		int y = this.getYCenter();
		this.setCenter(x + _xVelocity, y + _yVelocity);
		//System.out.println("MOVE METHOD");   // WORKS AS IS
		}
    }
